package OnlineExam.configuration;

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;


/**
 *  A common configuration that is needed by all the objects in the application is done here.
 */



public class Configure implements ServletContextListener
{
	public static long EXPIRY_TIME;
	public static String driver; 
	public static String url;
	public static String urlRoot;
	public static String initialConnectDBName;
   	public static String username;
	public static String password;
	public static String host;
	public static String from;
	public static String emailUsername;
	public static String emailPassword;
	public static String port;
	public static String emailConfirmationAddress;	
	
	/**
	 *  One time initialization of the frequently used database connection information.
	 */


	public void contextInitialized(ServletContextEvent event)
	{
		try
		{
			ServletContext application = event.getServletContext();

      		driver = application.getInitParameter("driverclass"); 
			urlRoot = application.getInitParameter("URLRoot");
     		url = application.getInitParameter("jdbcURL"); 
			initialConnectDBName = application.getInitParameter("initialConnectDBName");
      		username = application.getInitParameter("dbUsername"); 
      		password = application.getInitParameter("dbPassword");
			host = application.getInitParameter("host");
			from = application.getInitParameter("from");
			emailUsername = application.getInitParameter("emailUsername");
			emailPassword = application.getInitParameter ("emailPassword");
			port = application.getInitParameter ("port");
			emailConfirmationAddress = application.getInitParameter ("emailConfirmationAddress");
			EXPIRY_TIME = Long.parseLong(application.getInitParameter ("registrationTimeLimit"));

			Class.forName(driver);
		}

		catch (ClassNotFoundException cnfe)
		{
			System.out.println ("Exception " + cnfe);
		}
	}


	public void contextDestroyed (ServletContextEvent event)
	{

	}
}
